package com.gdut.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要使用的数据
 *
 * @author Drifiter
 * @create 2021-10-24 17:29
 */
//@Data
public class OrderConfirmVo {

    // 收货地址，ums_member_receive_address 表
    @Getter @Setter
    List<MemberAddressVo> address;

    // 购物清单，根据购物车页面传递过来的 skuIds 查询
    @Getter @Setter
    List<OrderItemVo> items;

    //发票记录....


    //优惠券信息...
    @Getter @Setter
    Integer integration;

    //防重令牌
    @Getter @Setter
    String orderToken;

    @Getter @Setter
    Map<Long,Boolean> stocks;

//    @Getter @Setter
//    Integer count;


    public Integer getCount(){
        Integer i = 0;
        if (items != null){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

//    BigDecimal total;//订单总额

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

//    BigDecimal payPrice;//应付价格

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
